/**
 * Candidate number: 35834
 */
package tv.starfu.game.states;

import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.input.InputManager;
import com.jme3.input.controls.AnalogListener;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
import com.jme3.system.AppSettings;

public class MenuState extends AbstractAppState implements AppState {

    private AssetManager assetManager;
    private Node localRootNode = new Node("MenuRootNode");
    private Node localGuiNode = new Node("MenuGuiNode");
    private Node rootNode;
    private Node guiNode;
    private ViewPort viewport;
    private InputManager inputManager;
    private AppSettings settings;
    private SimpleApplication app;

    /**
     * New Arcade state
     * @param app
     * @param settings 
     */
    public MenuState(SimpleApplication app, AppSettings settings) {
        this.guiNode = app.getGuiNode();
        this.rootNode = app.getRootNode();
        this.assetManager = app.getAssetManager();
        this.inputManager = app.getInputManager();
        this.viewport = app.getViewPort();
        this.settings = settings;
        this.app = app;
        app.setDisplayFps(true);
        app.setDisplayStatView(true);
    }

    @Override
    public void initialize(AppStateManager stateManager, Application app) {
        viewport.setBackgroundColor(ColorRGBA.Blue);
        super.initialize(stateManager, app);
        BitmapText text = drawHUD();
        guiNode.attachChild(localGuiNode);
    }

    public BitmapText drawHUD() {
        BitmapFont guiFont = assetManager.loadFont(
                "Interface/Fonts/Default.fnt");
        BitmapText displaytext = new BitmapText(guiFont);
        displaytext.setSize(guiFont.getCharSet().getRenderedSize());
        displaytext.move(10, displaytext.getLineHeight() + 200, 0);
        displaytext.setText("Menu Screen...press RETURN or SHIFT!!");
        localGuiNode.attachChild(displaytext);
        return displaytext;
    }

    @Override
    public void cleanup() {
        super.cleanup();
        app.setDisplayFps(false);
        app.setDisplayStatView(false);

    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        if (enabled) {
            guiNode.attachChild(localGuiNode);
            rootNode.attachChild(localRootNode);
        } else {
            guiNode.detachChild(localGuiNode);
            rootNode.detachChild(localRootNode);
        }
    }
}
